<template lang="">
    <el-card class="box-card" style="margin: 10px 0;">
        <div slot="header" class="clearfix">
            <!--" @tab-click="handleClick" -->
            <!-- 左侧内容 -->
            <el-tabs class="tab" v-model="activeName">
                <el-tab-pane label="销售额" name="sale">
                </el-tab-pane>

                <el-tab-pane label="访问量" name="visite">
                </el-tab-pane>

            </el-tabs>
            <!-- 右侧内容 -->
            <div class="right">
                <span @click="setDay">今日</span>
                <span @click="setWeek">本周</span>
                <span @click="setMonth">本月</span>
                <span @click="setYear">本年</span>
                <!-- 日历部分 -->
                <el-date-picker class="date" size='mini' type="daterange" range-separator="|" start-placeholder="开始日期"
                    end-placeholder="结束日期" v-model="date" value-format="yyyy-MM-dd">
                </el-date-picker>
            </div>
        </div>
        <!-- 销售额部分 -->
        <div>
            <el-row :gutter="10">
                <el-col :span="18">
                    <div class="charts" ref="charts">
                    </div>
                </el-col>
                <el-col :span="6">
                    <h3>门店{{title}}排行</h3>
                    <ul class="qs">
                        <li v-for="(userRank,index) in listState.userRank" :key="index">
                            <span class="rindex">{{userRank.no}}</span>
                            <span class="rvalue">{{userRank.name}}</span>
                            <span class="rdate">{{userRank.money}}</span>
                        </li>
                        
                    </ul>
                </el-col>
            </el-row>

        </div>
    </el-card>
</template>
<script>
import dayjs from 'dayjs';
import * as echarts from 'echarts';
import { mapState } from 'vuex';
export default {
  name: 'Sale',
  data() {
    return {
      activeName: 'sale',
      myCharts: null,
      date: [],
    };
  },
  mounted() {
    this.myCharts = echarts.init(this.$refs.charts);
    this.myCharts.setOption({
      title: {
        text: this.title + '趋势',
      },
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow',
        },
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true,
      },
      xAxis: [
        {
          type: 'category',
          data: this.listState.orderFullYearAxis,
          axisTick: {
            alignWithLabel: true,
          },
        },
      ],
      yAxis: [
        {
          type: 'value',
        },
      ],
      series: [
        {
          name: 'Direct',
          type: 'bar',
          barWidth: '60%',
          data: this.listState.orderFullYear,
          color: 'green',
        },
      ],
    });
  },
  computed: {
    title() {
      return this.activeName == 'sale' ? '销售额' : '访问量';
    },
    ...mapState({
      listState: (state) => state.home.list,
    }),
  },
  watch: {
    //   首次刷新展示数据
    listState() {},
    title() {
      //    重新修改的配置数据
      this.myCharts.setOption({
        title: {
          text: this.title,
        },
        xAxis: {
          data:
            this.title == '销售额'
              ? this.listState.orderFullYearAxis
              : this.listState.userFullYearAxis,
        },
        series: [
          {
            name: 'Direct',
            type: 'bar',
            barWidth: '60%',
            data:
              this.title == '销售额'
                ? this.listState.orderFullYear
                : this.listState.userFullYear,
            color: 'green',
          },
        ],
      });
    },
  },
  methods: {
    // 本天
    setDay() {
      const day = dayjs().format('YYYY-MM-DD');
      this.date = [day, day];
    },
    //本周
    setWeek() {
      const start = dayjs().day(1).format('YYYY-MM-DD');
      const end = dayjs().day(7).format('YYYY-MM-DD');
      this.date = [start, end];
    },
    // 本月
    setMonth() {
      const start = dayjs().startOf('month').format('YYYY-MM-DD');
      const end = dayjs().endOf('month').format('YYYY-MM-DD');
      this.date = [start, end];
    },
    //本年
    setYear() {
      const start = dayjs().startOf('year').format('YYYY-MM-DD');
      const end = dayjs().endOf('year').format('YYYY-MM-DD');
      this.date = [start, end];
    },
  },
};
</script>
<style scoped>
.clearfix {
  position: relative;
  display: flex;
  justify-content: space-between;
}

.tab {
  width: 100%;
}

.right {
  position: absolute;
  right: 0;
}

.date {
  width: 230px;
  margin: 0 20px;
}

.right span {
  margin: 0px 15px;
}

.charts {
  width: 100%;
  height: 300px;
}

.qs {
  list-style: none;
  width: 100%;
  height: 300px;
  padding: 0px;
}

.qs li {
  height: 8%;
  margin: 10px 0px;
}

.qs span:nth-child(1) {
  float: left;
  width: 19px;
  height: 16px;
  border-radius: 50%;
  text-align: center;
}

.rindex {
  /* z-index: 9999; */
  background: black;
  color: white;
}

.rvalue {
  padding: 0 25px;
}

.rdate {
  float: right;
}
</style>